<template>
  <el-card shadow="never" class="mb20">
    <div class="table-page-search-wrapper">
      <el-form :model="form" ref="form" :inline="true" label-width="80px">
        <el-row :gutter="16">
          <el-col :span="8">
            <el-form-item label="运行时间" prop="date">
              <el-date-picker
                style="width: 100%"
                v-model="date"
                type="daterange"
                range-separator="-"
                value-format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预警规则" prop="ruleId">
              <el-select clearable v-model="form.ruleId">
                <el-option
                  v-for="(item,index) in list"
                  :key="index"
                  :label="item.ruleName"
                  :value="item.ruleId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-tooltip class="item" effect="dark" content="查询" placement="top">
                <el-button icon="el-icon-search" type="primary" @click="handleSearch" />
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="重置" placement="top">
                <el-button icon="el-icon-refresh-right" @click="handleReset" />
              </el-tooltip>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
</template>

<script>
import { warningRuleAll } from '@/api/prewarning'
export default {
  data() {
    return {
      date: null,
      list: [],
      form: {
        startTime: null,
        endTime: null,
        ruleId: null
      }
    }
  },
  mounted() {
    warningRuleAll().then(res => {
      console.log('res', res)
      this.list = res.data
    })
    // this.date = this.timeDefault
    // this.handleSearch()
  },
  methods: {
    handleSearch() {
      if (this.date) {
        this.$set(this.form, 'startTime', this.date[0])
        this.$set(this.form, 'endTime', this.date[1])
      } else {
        this.$set(this.form, 'startTime', null)
        this.$set(this.form, 'endTime', null)
      }
      this.$emit('search', this.form)
    },
    handleReset() {
      this.$refs.form.resetFields()
      this.date = null
      this.handleSearch()
    }
  }
}
</script>
